package cn.itrip.controller;

import cn.itrip.DTO.*;
import cn.itrip.entity.ItripAreaDic;
import cn.itrip.entity.ItripHotel;
import cn.itrip.entity.ItripImage;
import cn.itrip.entity.ItripLabelDic;
import cn.itrip.service.*;
import cn.itrip.vo.R;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/hotel")
public class HotelController {

    @Resource
    private ItripHotelService itripHotelService;
    @Resource
    private ItripLabelDicService itripLabelDicService;
    @Resource
    private ItripAreaDicServcie itripAreaDicServcie;
    @Resource
    private ItripHotelFeatureService itripHotelFeatureService;
    @Resource
    private ItripHotelTradingAreaService itripHotelTradingAreaService;
    @Resource
    private ItripImageService itripImageService;

    @ApiOperation(value = "查询热门城市")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = HotcityDTO.class) })
    @GetMapping("/queryhotcity/{cityId}")
    public R queryHotCity(@PathVariable("cityId") String cityId){
        List<ItripAreaDic> areaDics = itripAreaDicServcie.queryTradeAreaHot(cityId);
        List<HotcityDTO> itripHotelDTOS = new ArrayList<HotcityDTO>();
        for (int i = 0;i<areaDics.size();i++) {
            HotcityDTO itripHotelDTO = new HotcityDTO();
            BeanUtils.copyProperties(areaDics.get(i),itripHotelDTO);
            itripHotelDTOS.add(itripHotelDTO);
        }
        return R.success(null,itripHotelDTOS);
    }

    @ApiOperation(value = "查询所有酒店特色")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = ItripLabelDicDTO.class) })
    @GetMapping("/queryhotelfeature")
    public R queryHotelFeature(){
        List<ItripLabelDic> queryhotelfeature = itripLabelDicService.queryHotelFeature();
        List<ItripLabelDicDTO> itripLabelDicDTOS = new ArrayList<ItripLabelDicDTO>();
        for (int i = 0;i<queryhotelfeature.size();i++) {
            ItripLabelDicDTO itripLabelDicDTO = new ItripLabelDicDTO();
            BeanUtils.copyProperties(queryhotelfeature.get(i),itripLabelDicDTO);
            itripLabelDicDTOS.add(itripLabelDicDTO);
        }
        return R.success(null,itripLabelDicDTOS);
    }

    @ApiOperation(value = "查询城市商圈")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = ItripAreaDicDTO.class) })
    @GetMapping("/querytradearea/{cityId}")
    public R queryTradeArea(@PathVariable("cityId") String cityId){
        List<ItripAreaDic> areaDics = itripAreaDicServcie.queryTradeArea(cityId);
        ArrayList<ItripAreaDicDTO> areaDicDTOS = new ArrayList<>();
        for (int i = 0;i<areaDics.size();i++) {
            ItripAreaDicDTO areaDicDTO = new ItripAreaDicDTO();
            BeanUtils.copyProperties(areaDics.get(i),areaDicDTO);
            areaDicDTOS.add(areaDicDTO);
        }
        return R.success(null,areaDicDTOS);
    }

    @ApiOperation(value = "查询酒店视频信息")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = VideoDescDTO.class) })
    @GetMapping("/getvideodesc/{hotelId}")
    public R getVideoDesc(@PathVariable("hotelId") Long hotelId){
        ItripHotel hotel = itripHotelService.getHotelByHotelId(hotelId);
            VideoDescDTO videoDescDTO = new VideoDescDTO();
            videoDescDTO.setHotelName(hotel.getHotelName());
            List<ItripLabelDic> list1;
            list1 = itripHotelFeatureService.getFeatureNameByHotelId(hotelId);
            List<String> list2 = new ArrayList<>();
            for (int z = 0;z<list1.size();z++) {
                list2.add(list1.get(z).getName());
            }
            videoDescDTO.setHotelFeatureList(list2);
            List<String> list3;
            list3 = itripHotelTradingAreaService.getTradingAreaNameList(hotelId);
            videoDescDTO.setTradingAreaNameList(list3);
        return R.success("获取酒店视频文字描述成功",videoDescDTO);
    }

    @ApiOperation(value = "查询酒店描述和特色")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = HotelDetailsDTO.class) })
    @GetMapping("/queryhoteldetails/{id}")
    public R queryHotelDetails(@PathVariable("id") Long id){
        ItripHotel hotel = itripHotelService.getHotelByHotelId(id);
        ArrayList<HotelDetailsDTO> hotelDetailsDTOS = new ArrayList<>();
            HotelDetailsDTO hotelDetailsDTO1 = new HotelDetailsDTO();
            hotelDetailsDTO1.setDescription(hotel.getDetails());
            hotelDetailsDTO1.setName("酒店介绍");
            hotelDetailsDTOS.add(hotelDetailsDTO1);
            List<ItripLabelDic> list1;
            list1 = itripHotelFeatureService.getFeatureNameByHotelId(id);
            for (int z = 0;z<list1.size();z++) {
                HotelDetailsDTO hotelDetailsDTO2 = new HotelDetailsDTO();
                hotelDetailsDTO2.setDescription(list1.get(z).getDescription());
                hotelDetailsDTO2.setName(list1.get(z).getName());
                hotelDetailsDTOS.add(hotelDetailsDTO2);
            }
        return R.success(null,hotelDetailsDTOS);
    }

    @ApiOperation(value = "查询酒店设施")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = HotelFacilitiesDTO.class) })
    @GetMapping("/queryhotelfacilities/{id}")
    public R queryHotelFacilities(@PathVariable("id") Long id){
        ItripHotel hotel = itripHotelService.getHotelByHotelId(id);
            HotelFacilitiesDTO hotelFacilitiesDTO = new HotelFacilitiesDTO();
            hotelFacilitiesDTO.setFacilities(hotel.getFacilities());
        return R.success(null,hotelFacilitiesDTO.getFacilities());
    }

    @ApiOperation(value = "查询酒店设施")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = HotelPolicyDTO.class) })
    @GetMapping("/queryhotelpolicy/{id}")
    public R queryHotelPolicy(@PathVariable("id") Long id){
        ItripHotel hotel = itripHotelService.getHotelByHotelId(id);
            HotelPolicyDTO hotelPolicyDTO = new HotelPolicyDTO();
            hotelPolicyDTO.setHotelPolicy(hotel.getHotelPolicy());
        return R.success(null,hotelPolicyDTO.getHotelPolicy());
    }

    @ApiOperation(value = "查询酒店图片")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK",response = ItripImageDTO.class) })
    @GetMapping("/getimg/{roomId}")
    public R getImg(@PathVariable("roomId") String roomId){
        List<ItripImage> list = itripImageService.getListByRoomId(roomId, "0");
        List<ItripImageDTO> itripImageDTOS = new ArrayList<>();
        for (int i = 0;i<list.size();i++){
            ItripImageDTO itripImageDTO = new ItripImageDTO();
            itripImageDTO.setImgUrl(list.get(i).getImgUrl());
            itripImageDTO.setPosition(list.get(i).getPosition());
            itripImageDTOS.add(itripImageDTO);
        }
        return R.success("获取酒店图片成功",itripImageDTOS);
    }
}